SingleLinePlugin   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
c 0
b 0
f 0
dl 0
loc 27
rs 10
wmc 3

1 Function

Rating   Name   Duplication   Size   Complexity  
A init 0 25 3
1
/*
2
 * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
3
 *
4
 *  Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
5
 *
6
 *  This program is free software: you can redistribute it and/or modify
7
 *  it under the terms of the GNU Affero General Public License as published
8
 *  by the Free Software Foundation, either version 3 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU Affero General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU Affero General Public License
17
 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
21
22
export default class SingleLinePlugin extends Plugin {
23
    init() {
24
        const editor = this.editor;
25
        const view = editor.editing.view;
26
        const viewDocument = view.document;
27
28
        //Listen to enter presses
29
        this.listenTo( viewDocument, 'enter', ( evt, data ) => {
0 ignored issues
show
Unused Code introduced by
The parameter data is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
30
            //If user presses enter, prevent the enter action
31
            evt.stop();
32
        }, { priority: 'high' } );
33
34
        //And clipboard pastes
35
        this.listenTo( viewDocument, 'clipboardInput', ( evt, data ) => {
36
            let dataTransfer = data.dataTransfer;
37
38
            //Clean text input (replace newlines with spaces)
39
            let input = dataTransfer.getData("text");
40
            let cleaned = input.replace(/\r?\n/g, ' ');
41
42
            //We can not use the dataTransfer.setData method because the old object is somehow protected
43
            data.dataTransfer = new DataTransfer();
0 ignored issues
show
Bug introduced by
The variable DataTransfer seems to be never declared. If this is a global, consider adding a /** global: DataTransfer */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
44
            data.dataTransfer.setData("text", cleaned);
45
            
46
        }, { priority: 'high' } );
47
    }
48
}